//
//  ViewController.m
//  PageController
//
//  Created by yu on 2018/4/6.
//  Copyright © 2018年 ma c. All rights reserved.
//

#import "ViewController.h"
#import "HGPageTitleView.h"
#import "HGPageContenView.h"
#import "UIColor+Extension.h"
@interface ViewController ()<HGPageTitleViewDelegate, HGPageContenViewDelegate>
@property (nonatomic, strong)HGPageContenView *contentView;
@property (nonatomic, strong)HGPageTitleView *titleView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    CGSize size = self.view.frame.size;
    _titleView = [[HGPageTitleView alloc] initWithFrame:CGRectMake(0, 64, size.width, 40) andTitles:@[@"资讯", @"精彩", @"活动", @"其他"]];
    _titleView.delegate = self;
    [self.view addSubview:_titleView];
    
    NSMutableArray *childVcs = [NSMutableArray new];
    for (int i = 0; i < 4; i++) {
        UIViewController *vc = [[UIViewController alloc] init];
        vc.view.backgroundColor = [UIColor red:arc4random() % 255 green:arc4random() % 255 blue:arc4random() % 255];
        [childVcs addObject:vc];
    }
    _contentView = [[HGPageContenView alloc] initWithFrame:CGRectMake(0, 64 + 40, size.width, size.height - 64 - 40) childViewControllers:childVcs andParentViewController:self];
    _contentView.delegate = self;
    [self.view addSubview:_contentView];
    
}


- (void)pageTitleView:(HGPageTitleView *)pageTitleView selectedIndex:(NSInteger)index {
    NSLog(@"%ld", index);
    [self.contentView pageContentViewScrollToCurrentIndex:index];
}

- (void)pageContenViewScrollProgress:(CGFloat)progress sourceIndex:(NSInteger)sourceIndex targetIndex:(NSInteger)targetIndex {
    [self.titleView setTitleViewWithProgress:progress sourceIndex:sourceIndex targetIndex:targetIndex];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}






@end
